package com.googlecode.bip.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.naming.NamingException;
import com.googlecode.bip.dao.utils.Listable;
import com.googlecode.bip.entity.ITopic;
import com.googlecode.bip.entity.Local;
import com.googlecode.bip.entity.Topic;

/**
 *
 * @author Claude CHOISNET
 */
public abstract class TopicDAO
        implements Listable<ITopic>
{
    private static final long serialVersionUID = 1L;

    /**
     * Build TopicDAO
     */
    protected TopicDAO()
    {
    }

    @Override //Listable<ITopic>
    public ITopic newInstance(final ResultSet rSet )
        throws SQLException
    {
        return new Topic().set( rSet );
    }

    /**
     * Returns an @{link ITopic} according to idtopic and idlocal
     *
     * @param idtopic   idtopic (int value)
     * @param idlocal   idlocal (2 characters String)
     * @return an @{link ITopic} according to idtopic and idlocal
     * @throws NamingException if any
     * @throws SQLException if any
     */
    public abstract ITopic findTopic( int idtopic, String idlocal )
        throws NamingException, SQLException;

    /**
     * Returns an @{link ITopic} according to idtopic and idlocal
     *
     * @param idtopic	idtopic (int value)
     * @param local   	Local object to use
     * @return an @{link ITopic} according to idtopic and local
     * @throws NamingException if any
     * @throws SQLException if any
     */
    public ITopic findTopic( int idtopic, Local local )
        throws NamingException, SQLException
    {
        return findTopic( idtopic, local.getIdLocal() );
    }

    /**
     * Returns all translation for a @{link ITopic}
     *
     * @param idtopic idtopic to find
     * @return a List with translation for the giving idtopic
     * @throws SQLException if any
     * @throws NamingException if any
     */
    public abstract List<ITopic> findTopic( int idtopic )
        throws SQLException, NamingException;


    /**
    *Return all topics created so far
    *
    * @return A list of topics
    * @throws SQLException if any
    * @throws NamingException if any
    */
   public abstract List<ITopic> getAllTopics(  )
       throws SQLException, NamingException;

    /**
     * Insert a new Topic (must not exist)
     * <br/>
     * {@link ITopic#getIdTopic()} value is ignored by insertion (must be equal 0)
     * <br/>
     * After database insert this method update {@link ITopic#getIdTopic()} content
     * with the index created by database.
     *
     * @param itopic ITopic  to add in database
     * @return true if insert succeed
     * @throws NamingException if any
     * @throws SQLException if any
     */
    public abstract boolean insertTopic( final ITopic itopic )
        throws NamingException, SQLException;

    /**
     * Remove Topic from database, if no more use
     *
     * @param topic
     * @return
     * @throws NamingException if any
     * @throws SQLException if any
     */
    public boolean deleteTopic( final ITopic topic )
        throws NamingException, SQLException
    {
        return deleteTopic( topic.getIdTopic() );
    }

    /**
     * Remove Topic from database, if no more use
     *
     * @param idtopic
     * @return
     * @throws NamingException if any
     * @throws SQLException if any
     */
    public abstract boolean deleteTopic( final int idtopic )
       throws NamingException, SQLException;

    /**
     * Remove Topic translation from database
     *
     * @param idtopic
     * @param idlocal
     * @return
     * @throws NamingException if any
     * @throws SQLException if any
     */
    public abstract boolean deleteTopicLocal( int idtopic, String idlocal )
       throws NamingException, SQLException;

    /**
     *
     * @param itopic
     * @return
     * @throws NamingException if any
     * @throws SQLException if any
     */
    public abstract boolean updateTopic( final ITopic itopic )
        throws NamingException, SQLException;

}

